package com.excel.poi.ali;

import com.excel.poi.ali.inter.ExcelAnalyser;
import com.excel.poi.ali.inter.ExcelAnalyserImpl;

import java.io.InputStream;

/**
 * @author zw
 * @Description Excel阅读器都是在事件模式下读取的。
 * @create /2022/3/25
 */
public class ExcelReader {

    /**
     * 分析器(接口）看使用那种分析器
     */
    private ExcelAnalyser analyser ;
    /**
     * 1 第一步 创建excel实现
     *
     * @param in
     * @param eventListener
     * @param trim
     */
    public ExcelReader(InputStream in, Class c1,AnalysisEventListener eventListener, boolean trim) {
        validateParam(in,c1, eventListener);
        analyser = new ExcelAnalyserImpl(in, c1,eventListener, trim);
    }
    /**
     * 读取excel
     * @throws Exception
     */
    public void read() throws Exception {
        analyser.analysis();
    }

    /**
     * 验证参数
     *
     * @param in
     * @param eventListener
     */
    private void validateParam(InputStream in,  Class c1, AnalysisEventListener eventListener) {
        if (eventListener == null) {
            throw new IllegalArgumentException("AnalysisEventListener can not null");
        } else if (in == null) {
            throw new IllegalArgumentException("InputStream can not null");
        }else if (c1 == null) {
            throw new IllegalArgumentException("Class can not null");
        }
    }
}
